package com.lpf.error;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map;

public class ErrorMsgUtil {

    public static String getErrorMsg(Throwable throwable) {
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        try {
            throwable.printStackTrace(printWriter);
            return stringWriter.toString();
        } finally {
            printWriter.close();
        }
    }

    public static void main(String[] args) {
        Map map = null;
        try {
            map.get("");
        } catch (Exception e) {
            String errorMsg = getErrorMsg(e);
            System.out.println(errorMsg);
        }
    }
}